import React from "react";

import PageContent from '../../PageContent';

import { ajax, openErrorNotification, openSuccessNotification, showResultMessage, isNotNull, isNull } from '../../common';

import ClassDefineDataTablePanel from './ClassDefineListDataTablePanel';

import ClassDefineEditPanel from './ClassDefineEditPanel';

import ClassCourseConfigPanel from './ClassCourseConfigPanel';

import ClassStudentConfigPanel from './ClassStudentConfigPanel';
/** 
 * 班级定义管理
*/
export default class ClassDefineManageApp extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			formParams : {
				campusId : 0,
			}
		}
    }

    actionHandler = (actionEvent,panelInstance) => {

		return {
						        
			refresh : () => {
				panelInstance.loadData();
			},
									        
			addNew : () => {
				panelInstance.addNew();
				//panelInstance.props.pageHistory.push('/addNewClassDefine');
			},
									        
			doDelete : () => {
				panelInstance.doDelete(isNotNull(actionEvent.params) ? actionEvent.params.id : null);
			},
													
			doEdit : () => {
				panelInstance.doEdit(actionEvent.params);
			},						
			doSave : () => {
				panelInstance.doSave();
			},
			setClassCourse : () => {
				panelInstance.props.pageHistory.push('/setClassCourse',{classDefine : actionEvent.params});
			},
			setClassStudent : () => {
				panelInstance.props.pageHistory.push('/setClassStudent',{classDefine : actionEvent.params});
			},
												
		};
	}

	onValuesChange = (changedValues, allValues) => {
		if('campusId' in changedValues){
			this.classDefineListTableRef.dataFormRef.setFormFieldParams('classRoomId',{campusId : changedValues['campusId']});
			//this.setState({formParams : {campusId : changedValues['campusId']}});
		}
	}

	render() {

		const formParams = this.state;

		const pageContentMap = {
			'/': {
				text: '班级',
				icon: 'users',
				getComponent:  (owner, props) =>{
					return (
						<ClassDefineDataTablePanel 
							{...props} pageHistory={props.history}
							ref={inst => this.classDefineListTableRef = inst}
							actionHandler={this.actionHandler} 
							onValuesChange={this.onValuesChange}
							formParams={formParams}
						/>
					);
				}
			},
			'/addNewClassDefine' : {
				text: '新增班级',
				icon: 'users',
				getComponent:  (owner, props) => {
					return (
						<ClassDefineEditPanel 
							{...props} pageHistory={props.history}
							ref={inst => this.classDefineEditPanelRef = inst}
						/>
					);
				}
			},
			'/setClassCourse' : {
				text: '设置班级课程',
				icon: 'book',
				getComponent:  (owner, props) => {
					return (
						<ClassCourseConfigPanel 
							{...props} pageHistory={props.history}
							ref={inst => this.classCourseConfigPanelRef = inst}
						/>
					);
				}
			},
			'/setClassStudent' : {
				text: '设置班级学员',
				icon: 'child',
				getComponent:  (owner, props) => {
					return (
						<ClassStudentConfigPanel 
							{...props} pageHistory={props.history}
							ref={inst => this.classCourseConfigPanelRef = inst}
						/>
					);
				}
			},
		}

        return (
            <PageContent {...this.props} pageInstance={this} contentMap={pageContentMap} >
                
            </PageContent>
        );
    }
}